package com.yulian.yulianbackend.common;

import lombok.Data;

import java.io.Serializable;

/**
 * 通用返回表
 *
 * @author yulian174
 * @version 1.0
 */
//支持序列化接口
//注解作用：生成getter和setter方法
@Data
public class BaseResponse<T> implements Serializable {

    private int code; //业务状态码
    private T data; //数据 , 泛型的通用返回类型(user, long, Integer(可重用))
    private String message; //后端返回信息
    private String description; //具体错误信息描述

    //生成构造器，方便创建对象

    public BaseResponse(int code, T data, String message, String description) {
        this.code = code;
        this.data = data;
        this.message = message;
        this.description = description;
    }

    public BaseResponse(int code, T data, String message) {
        this(code, data, message, "");
    }

    public BaseResponse(int code, T data) {
        this(code, data, "", "");
    }

    public BaseResponse(ErrorCode errorCode) {
        this(errorCode.getCode(), null, errorCode.getMessage(), errorCode.getDescription());
    }
}
